var swiper_wrapper = document.querySelector(".swiper-wrapper");

var requestOptions = {
  method: "GET",
  redirect: "follow",
};

fetch(`${apirUrl}/api/getrecommendnews?pageViews=1&limit=20`, requestOptions)
  .then((response) => response.json())
  .then((result) => {
    console.log(result.news);

    //遍历数据
    for (let i = 0; i < result.news.length; i++) {
      var swiper_card_html = `
        <div class="swiper-slide">
                  <div class="slide-img"><img src="${apirUrl}${result.news[i].imgsrc}"
                      alt=""></div>
                  <div class="swiper_title">
                    <h3><a href="${serverUrl}/view.html?newsid=${result.news[i].newsid}">${result.news[i].title}</a></h3>
                  </div>
                  <div class="siwper_time">
                    <p>${result.news[i].date}</p>
                  </div>
                  <div class="siwper_info">
                    <span class="keyword">${result.news[i].keyword}</span><span class="page_views"><i class="bi bi-eye-fill"></i>${result.news[i].pageViews}</span>
                  </div>
                </div>
        `;
      swiper_wrapper.innerHTML += swiper_card_html;
      var swiper = new Swiper(".mySwiper", {
        effect: "cards",
        grabCursor: true,
      });
    }
  })
  .catch((error) => console.log("error", error));

var swiper_lunfan = document.querySelector("#swiper_lunfan");
var requestOptionsLunfan = {
  method: "GET",
  redirect: "follow",
};

fetch(
  `${apirUrl}/api/getrecommendnews?pageViews=1&limit=20`,
  requestOptionsLunfan
)
  .then((response) => response.json())
  .then((result) => {
    console.log(result.news);

    //遍历数据
    for (let i = 0; i < result.news.length; i++) {
      var swiper_lunfan_html = `
      <div class="swiper-slide"><a href="${serverUrl}/view.html?newsid=${result.news[i].newsid}">
      <img
        src="${apirUrl}${result.news[i].imgsrc}">
    </a>
  </div>
        `;
      swiper_lunfan.innerHTML += swiper_lunfan_html;
      var swiper = new Swiper(".mySwiper-lunfan", {
        pagination: {
          el: ".swiper-pagination",
          type: "progressbar",
        },
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
      });
    }
  })
  .catch((error) => console.log("error", error));
